package NWPackage;

public class RealVoteMatrix extends Matrix {

	public RealVoteMatrix() {
	}

	public RealVoteMatrix(Cell[] cells) {
		super(cells);
	}
	
	public void initial(RealVoteCell[] cells) {
		
		//
		this.cells = cells;
	}
	public Cell getCell(int index)
	{
		if (index < cells.length)
			return (ProbabilityCell)cells[index];
		return null;
	}
	
	public int getLength(){
		return super.cells.length;
	}

	public String getRealVote(PairPreferdCandidateCell query) throws NullPointerException{

		String[] pairCandidates = query.getCandidates();
	
		RealVoteCell realVote= getAgentVote(query.getAgentName());
		
		/*double d_cand1 = Double.parseDouble(pairCandidates[0]);
		double d_cand2 = Double.parseDouble(pairCandidates[1]);
		String s_cand1 = Double.toString(d_cand1);
		String s_cand2 = Double.toString(d_cand2);		
		int index_0 = realVote.getIndexOf(s_cand1);
		int index_1 = realVote.getIndexOf(s_cand2);*/
		
		int index_0 = realVote.getIndexOf(pairCandidates[0]);
		int index_1 = realVote.getIndexOf(pairCandidates[1]); 
		if (index_0 > index_1)
			return pairCandidates[0];
		else
			return pairCandidates[1];
		
	}

	private RealVoteCell getAgentVote(String agentName) {
		for (RealVoteCell vote : (RealVoteCell[])this.cells) {
			String thisAgent = vote.getAgentName();
			//int thisAgent_int = Integer.parseInt(thisAgent);
			double thisAgent_int = Double.parseDouble(thisAgent);
			//int agentName_int = Integer.parseInt(agentName);
			double agentName_int = Double.parseDouble(agentName);
			//if (thisAgent.equals(agentName))   //Lihi changed this from strings to ints, 6.2.13
			if (thisAgent_int == agentName_int)
				return vote;
		}
		return null;
	}
	
}
